import BaseController from '../../core/baseController';
import { getCurrentStimp } from '../../utils/index';


export default class RateController extends BaseController {
  constructor(ctx) {
    super(ctx)
    this.service = ctx.service.wx.rate;
    this.modelPrefix = 'rate';
  }

  //通用列表
  async list() {
    const { page, pageSize } = this.ctx.validateReq(
      `${this.modelPrefix}.list`,
    ).query;

    const where = {};
    const result = await this.service.index(page, pageSize, where);

    if (result) {
      this.ctx.success({
        data: result
      });
    }
  }



  //创建
  async create() {
    const { body } = this.ctx.validateReq(`${this.modelPrefix}.create`);
    const { order_id } = body;

    const stemp = getCurrentStimp();
    Object.assign(body, {
      create_at: stemp,
      update_at: stemp,
    });
    const result = await this.service.create(body);
    // 评价订单
    await this.ctx.service.wx.order.model.update(
      { status: 'RATE' },
      { where: { order_id } }
    )

    if (result) {
      this.ctx.success({
        data: {
          id: result.id,
        },
        status: 201,
      });
    }
  }

}
